package com.xuexi.controller;

import com.easygo.utils.PageUtils;
import com.xuexi.api.TypeTemplateClient;
import com.xuexi.easygo.pojo.TypeTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@Scope("prototype")
public class TypeTemplateController {


    @Autowired
    TypeTemplateClient templateClient;

    @RequestMapping("typeTemplate_page")
    @ResponseBody
    public String getTypeTemplatePage(@RequestParam(defaultValue = "1", required = false,value = "pageIndex") Integer pageIndex,
                                                       @RequestParam(defaultValue = "5", required = false,value = "pageSize") Integer pageSize,
                                                       @RequestParam(defaultValue = "", required = false,value = "name") String name, Model model){
        PageUtils<TypeTemplate> pageUtils = templateClient.getTypeTemplatePage(pageIndex, pageSize, name);
        model.addAttribute("pageUtils",pageUtils);
        model.addAttribute("name",name);
        return "type_template";
    }

    @RequestMapping("typeTemplate_all")
    @ResponseBody
    public List<TypeTemplate> getTypeTemplates(){
        return templateClient.getTypeTemplates();
    }
}
